﻿//This filter has been tested and seems to work correctly

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Convolution 
    /// </summary>
    public class LonelyHoles : BaseImageFilter
    {
        protected int m_nPixelValue = 8;

        /// <summary>
        /// Initializes a new instance of the <see cref="LonelyHoles"/> class.
        /// </summary>
        public LonelyHoles()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LonelyHoles"/> class.
        /// </summary>
        /// <param name="_lonelyHoles">The _lonely holes.</param>
        internal LonelyHoles(LonelyHoles _lonelyHoles)
        {
        }

        /// <summary>
        /// Gets or sets the pixel value.
        /// </summary>
        /// <value>The pixel value.</value>
        public int PixelValue
        {
            get { return m_nPixelValue; }
            set { m_nPixelValue = value; }
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmap = _bitmap;
            CConvMatrix convMatrix = new CConvMatrix();
            convMatrix.TopLeft = 1;
            convMatrix.TopMid = 1;
            convMatrix.TopRight = 1;
            convMatrix.MidLeft = 1;
            convMatrix.Pixel = -m_nPixelValue;
            convMatrix.MidRight = 1;
            convMatrix.BottomLeft = 1;
            convMatrix.BottomMid = 1;
            convMatrix.BottomRight = 1;
            new Convolution3x3(convMatrix).Execute(bitmap);
            return _bitmap;
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new LonelyHoles(this);
        }
    }
}
